package cn.powerone.scm.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmAttachmentTemplate;
import cn.powerone.scm.service.IScmAttachmentTemplateService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 全局附件模板Controller
 * 
 * @author PowerOne
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/scm/scmAttachmentTemplate")
public class ScmAttachmentTemplateController extends BaseController
{
    @Autowired
    private IScmAttachmentTemplateService scmAttachmentTemplateService;

    /**
     * 查询全局附件模板列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmAttachmentTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmAttachmentTemplate scmAttachmentTemplate)
    {
        startPage();
        List<ScmAttachmentTemplate> list = scmAttachmentTemplateService.selectScmAttachmentTemplateList(scmAttachmentTemplate);
        return getDataTable(list);
    }

    /**
     * 导出全局附件模板列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmAttachmentTemplate:export')")
    @Log(title = "全局附件模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmAttachmentTemplate scmAttachmentTemplate)
    {
        List<ScmAttachmentTemplate> list = scmAttachmentTemplateService.selectScmAttachmentTemplateList(scmAttachmentTemplate);
        ExcelUtil<ScmAttachmentTemplate> util = new ExcelUtil<ScmAttachmentTemplate>(ScmAttachmentTemplate.class);
        util.exportExcel(response, list, "全局附件模板数据");
    }

    /**
     * 获取全局附件模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:scmAttachmentTemplate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmAttachmentTemplateService.selectScmAttachmentTemplateById(id));
    }

    /**
     * 新增全局附件模板
     */
    @PreAuthorize("@ss.hasPermi('scm:scmAttachmentTemplate:add')")
    @Log(title = "全局附件模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmAttachmentTemplate scmAttachmentTemplate)
    {
        return toAjax(scmAttachmentTemplateService.insertScmAttachmentTemplate(scmAttachmentTemplate));
    }

    /**
     * 修改全局附件模板
     */
    @PreAuthorize("@ss.hasPermi('scm:scmAttachmentTemplate:edit')")
    @Log(title = "全局附件模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmAttachmentTemplate scmAttachmentTemplate)
    {
        return toAjax(scmAttachmentTemplateService.updateScmAttachmentTemplate(scmAttachmentTemplate));
    }

    /**
     * 删除全局附件模板
     */
    @PreAuthorize("@ss.hasPermi('scm:scmAttachmentTemplate:remove')")
    @Log(title = "全局附件模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmAttachmentTemplateService.deleteScmAttachmentTemplateByIds(ids));
    }
}
